package com.fafi.selfmvc.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GlobalException {
	@ExceptionHandler(value={java.lang.ArithmeticException.class})
	public ModelAndView arithmeticExceptionHandler(Exception e) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("error",e.toString()+"--全局");
		mv.setViewName("error");
		return mv;
	}

	/**
	 * 如果 @ExceptionHandler 注解中未声明要处理的异常类型，则默认为参数列表中的异常类型
	 * @param e
	 * @return
	 */
	@ExceptionHandler()
	@ResponseBody
	String handleException(Exception e){
		return "Exception Deal! " + e.getMessage()+e.getCause().getMessage();
	}
}
